home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CU Amiga Super CD-ROM 27
/
CU Amiga Magazine's Super CD-ROM 27 (1998)(EMAP Images)(GB)[!][issue 1998-10].iso
/
CUCD
/
Online
/
News
/
Thor
/
rexx
/
ShowHTML.thor
< prev
next >
Wrap
Text File
|
1997-09-22
|
8KB
|
347 lines
/*
** $VER: ShowHTML.thor 1.2 (22.9.97)
**
** by Eirik Nicolai Synnes <eirikns@ifi.uio.no>
**
** ShowHTML.thor will send a HTML document in the message currently displayed
** in Thor's main window to a web browser. First it searches for a browser
** already in memory and uses this one, uniconifying it if necessary. If no
** browser is active it will launch the browser configured using CfgHTTP.thor.
**
** Currenly ShowHTML.thor recognizes IBrowse, AWeb, Voyager and AMosaic.
**
**
** Fixed in 1.2:
**
** o If ShowHTML wanted to display a requestor it would fail with
** an ARexx error
**
**
** New in 1.1:
**
** o HTML search routines vastly improved
** o Added support for Voyager (2.88 tested, might not work with earlier
** versions)
** o Added support for AMosaic (not tested)
** o Now uses CfgHTTP.thor's configuration file to figure out how to start
** the browser
** o Browser window is always brought to front and activated (if the
** browser's ARexx port support it)
** o Lots of minor enhancements and bug fixes
**
**
** Todo:
**
** o Delete shows "Delete returned 20" if it couldn't delete the temporary
** file. Is it possible to get rid of this?
**
** o See if it is possible to wait for something in order to avoid
** temp file getting deleted before the browser has loaded it
**
** o Add a WaitForPort after running browser
**
** o Figure out a flexible method to support inline pictures
** (
** Netscape:
** <IMG SRC="cid:picid">
** Picture attachment has Content-ID:<picid>
** )
**
*/
options results
options failat 31
signal on break_c
signal on halt
signal on error
globals = 'fileopen filename outfile THOR.LASTERROR BBSREAD.LASTERROR thorport msgtext. wwwcmd wwwport globals'
fileopen = 0
filename = 'T:SaveHTML.' || pragma('ID') || '.html'
/*
** See if I'm run from Thor
*/
if (left(address(), 5) = 'THOR.') then thorport = address()
else do
say 'This script must be run from Thor.'
exit(20)
end
/*
** Find/open BBSREAD ARexx port
*/
if ~(show('P', 'BBSREAD')) then do
address(command)
'Run >NIL: `GetEnv THOR/THORPath`bin/LoadBBSRead'
'WaitForPort BBSREAD'
if (rc ~= 0) then displayerror(30, 'SortMail', 'Couldn''t open BBSREAD''s ARexx port.')
end
call loadprefs()
/*
** Read the current message
*/
address(thorport)
'CURRENTMSG STEM 'curmsg
if (rc ~= 0) then call fail('Couldn''t detect a current message.')
address(bbsread)
'READBRMESSAGE "'curmsg.BBSNAME'" "'curmsg.CONFNAME'" 'curmsg.MSGNR' TEXTSTEM 'msgtext
if (rc ~= 0) then call fail('Couldn''t read message:\n'BBSREAD.LASTERROR)
/*
** Find out what browser(s) is/are active
*/
call findbrowser()
/*
** Find a text/html part
*/
if ~(findhtml('msgtext')) then do
if (symbol('msgtext.TEXT.COUNT') = 'VAR') & (msgtext.TEXT.COUNT > 0) then do
address(thorport)
'REQUESTNOTIFY TEXT "No text/html message part found.\nDo you want to send the first\nmessage part to the browser?" BT "Yes|No"'
if (rc ~= 0) then do
say 'Couldn''t open requester: 'THOR.LASTERROR
exit(0)
end
if (result = 1) then call savemsg('msgtext')
else exit(0)
end
else fail('No text/html message part found.')
end
/*
** Display HTML document
*/
if symbol('wwwport') ~= 'VAR' then do
address command 'Run <NIL: >NIL: 'wwwcmd' file://localhost/' || filename
if rc ~= 0 then fail('Failed to run browser.')
end
else do
address(wwwport)
select
when wwwport = 'VOYAGER' then 'OPENURL file://localhost/' || filename
when wwwport = 'IBROWSE' then 'GOTOURL file://localhost/' || filename
when left(wwwport, 5) = 'AWEB.' then 'OPEN URL file://localhost/' || filename || ' RELOAD'
when left(wwwport, 8) = 'AMOSAIC.' then 'JUMP URL file://localhost/' || filename
otherwise nop
end
if (rc ~= 0) then call fail('Browser failed to display document.')
end
/*
** Activate browser window
*/
if (symbol('wwwport') ~= 'VAR') then call findbrowser
address(wwwport)
select
when (wwwport = 'VOYAGER') then do
'SHOW'
'ACTIVATE'
end
when (wwwport = 'IBROWSE') then do
'SHOW'
'SCREENTOFRONT'
'ACTIVATE'
end
when (left(wwwport, 5) = 'AWEB.') then do
'WINDOWTOFRONT'
'SCREENTOFRONT'
'ACTIVATEWINDOW'
end
when (left(wwwport, 8) = 'AMOSAIC.') then do
'SHOW'
'ACTIVATE'
end
otherwise nop
end
/*
** Clean up and exit
*/
cleanup:
break_c:
halt:
error:
if fileopen = 1 then call close(outfile)
/*
** See if the file can be deleted. Checks every 10 seconds.
*/
if exists(filename) then do
address(command)
'Wait 20'
do i = 1 to 6
'Wait 10'
'Delete >NIL: "'filename'"'
if (rc = 0) then leave i
end
end
exit(0)
/****************************************************************************
********************************** Procedures ********************************
***************************************************************************/
/**
*** Find the first text/html part
**/
findhtml: interpret 'procedure expose 'globals
parse arg tstem
foundct = 0
if (symbol(tstem'.COMMENT.COUNT') = 'VAR') & (value(tstem'.COMMENT.COUNT') > 0) then do i = 1 to value(tstem'.COMMENT.COUNT') while foundct = 0
curline = upper(value(tstem'.COMMENT.i'))
if (subword(curline, 1, 1) = 'CONTENT-TYPE:') & (compress(subword(curline, 2, 1), ';') = 'TEXT/HTML') then foundct = 1
end
if (upper(value(tstem'.BINARY.DESC')) = 'TEXT/HTML') then foundct = 1
if foundct = 1 then do
call savemsg(tstem)
return(1)
end
else if (symbol(tstem'.PART.COUNT') = 'VAR') & (value(tstem'.PART.COUNT') > 0) then do i = 1 to value(tstem'.PART.COUNT')
newstem = tstem || '.PART.' || i || '.MSG'
call findhtml(newstem)
if (result = 1) then return(1)
end
return(0)
/**
*** Save a messagepart to disk
**/
savemsg: interpret 'procedure expose 'globals
parse arg htmltext
/* Write text body */
if (symbol(htmltext'.TEXT.COUNT') = 'VAR') then do
cnt = value(htmltext'.TEXT.COUNT')
if (cnt > 0) then do
fileopen = open(outfile, filename, 'W')
if ~(fileopen) then do
call fail('Couldn''t open "' || filename || '" for writing.')
return(20)
end
do i = 1 to cnt
call writeln(outfile, value(htmltext'.TEXT.'i))
end
call close(outfile)
end
else if (symbol(htmltext'.PART.1.BINARY') = 'VAR') & (value(htmltext'.PART.1.BINARY.DESC') = 'text/html') then do
htmlpath = value(htmltext'.PART.1.BINARY')
if ~(exists(htmlpath)) then fail('text/html part was deleted or not found.')
else address command 'Copy "'htmlpath'" TO "'filename'" QUIET'
end
else fail('text/html part was empty.')
end
return(0)
/*
** Find an active browser, run one if none is found
*/
findbrowser: interpret 'procedure expose 'globals
/* Go through available ports */
ports = show('P')
do i = 1 to words(ports)
if left(subword(ports, i), 5) = 'AWEB.' then wwwport = subword(ports, i, 1)
if left(subword(ports, i), 8) = 'AMOSAIC.' then wwwport = subword(ports, i, 1)
if left(subword(ports, i), 7) = 'VOYAGER' then wwwport = subword(ports, i, 1)
if left(subword(ports, i), 7) = 'IBROWSE' then wwwport = subword(ports, i, 1)
if symbol('wwwport') = 'VAR' then break
end
if left(subword(ports, i), 5) = 'AWEB.' then do
address(wwwport)
'GET ACTIVEPORT'
if (rc = 0 ) then wwwport = result
end
return(0)
/*
** Display an error message and exit
*/
fail: interpret 'procedure expose 'globals
parse arg errtext
address(thorport)
'REQUESTNOTIFY TEXT "'errtext'" BUTTONTEXT "Abort"'
if (rc ~= 0) then do
say 'Couldn''t open error requester: 'THOR.LASTERROR
say 'Original error was: 'errtext
end
signal cleanup
/*
** Load preferences saved by CfgHTTP.thor
*/
loadprefs: interpret 'procedure expose 'globals
cfgfile = 'ENV:Thor/http.config'
if ~(exists(cfgfile)) then do
address(thorport)
'REQUESTNOTIFY TEXT "Could not find the configuration file.\nRun CfgHTTP to create one or quit." BT "CfgHTTP|Quit"'
if (rc = 0) & (result = 1) then address command 'rx `GetEnv THOR/THORPath`rexx/cfghttp.thor'
exit(0)
end
else do
call open(prf, cfgfile, 'R')
do until eof(prf)
line = readln(prf)
if upper(word(line, 1)) = 'BROWSEREXE' then wwwcmd = subword(line, 2)
end
call close(prf)
end
return(0)